package slerp;

import java.util.EnumMap;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import org.lwjgl.input.Keyboard;

/**
 *
 * @author Pasta
 */
public class Keymap {
    Map keys;
    LinkedList pressed;
    public enum Key {
        MOVE_UP, MOVE_DOWN, MOVE_RIGHT, MOVE_LEFT, JUMP, SPRINT, MENU
    }
    
    public Keymap() {
        keys = new EnumMap<Key, Keyboard>(Key.class);
        pressed = new LinkedList<Key>();
        keys.put(Key.MOVE_UP, Keyboard.KEY_W);
        keys.put(Key.MOVE_DOWN, Keyboard.KEY_S);
        keys.put(Key.MOVE_RIGHT, Keyboard.KEY_D);
        keys.put(Key.MOVE_LEFT, Keyboard.KEY_A);
        keys.put(Key.JUMP, Keyboard.KEY_SPACE);
        keys.put(Key.SPRINT, Keyboard.KEY_LSHIFT);
        keys.put(Key.MENU, Keyboard.KEY_ESCAPE);
    }
    public LinkedList<Key> getPressed() {
        return pressed;
    }
    public void getInput() {
        while(Keyboard.next()) {
            for(Key k : Key.values()) {
                if(Keyboard.getEventKeyState()) {
                    if(Keyboard.getEventKey() == keys.get(k)) {
                        pressed.add(k);
                        System.out.println(k.name() + " is pressed");
                    }
                } else {
                    if(Keyboard.getEventKey() == keys.get(k)) {
                        pressed.remove(k);
                    }
                }
            }
        }
    }
}
